/*
 * Copyright (C) 2013 Tomi
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package rpg.ui.components;

import java.util.ArrayList;

/**
 *
 * @author Tomi
 */
public class ComponentGroup {

    private ArrayList<Component> components = new ArrayList();
    private ISelectOne selection = null;

    public ComponentGroup() {
    }

    public void clear() {
        components.clear();
    }

    public void addComponent(Component c) {
        components.add(c);
    }

    public Integer size() {
        return components.size();
    }

    public Boolean isEmpty() {
        return components.isEmpty();
    }

    public void setSelectedComponent(ISelectOne newSelection, boolean b) {
        if (b && newSelection != null && newSelection != selection) {
            ISelectOne oldSelection = selection;
            selection = newSelection;
            if (oldSelection != null) {
                oldSelection.setChecked(false);
                ((Component)oldSelection).redraw();
            }
            newSelection.setChecked(true);
            ((Component)newSelection).redraw();
        }
    }
    
    public Component getSelectedComponent(){
        return (Component) selection;        
    }
}
